<%
  unless (hide_submit ||= false)
    submit_button_text  ||= t('.save')
    submit_button_id    ||= "submit_button"
    submit_button_title ||= nil
  end

  hide_cancel = from_dialog? unless defined?(hide_cancel).presence

  unless hide_cancel
    cancel_button_text  ||= t('.cancel')
    unless defined?(cancel_title)
      cancel_title = t('.cancel_lose_changes')
    end
    cancel_button_id    ||= "cancel_button"
    cancel_url          ||= (((back = url_for(:back)).include?('javascript') or action_name =~ /^(create|update)$/) ? refinery.send(Refinery.route_for_model(f.object.class, :plural => true)) : back)
  end

  continue_editing = defined?(continue_editing) ? continue_editing : (f.object.present? and f.object.persisted?)

  unless defined?(hide_delete).presence
    hide_delete = (from_dialog? or
                   f.object.nil? or (f.object.respond_to?(:persisted?) ? !f.object.persisted? : f.object.new_record?) or
                   (f.object.respond_to?(:deletable?) && !f.object.deletable?))
  end

  unless hide_delete
    delete_button_text  ||= t('.delete')
    delete_title        ||= nil
    delete_confirmation ||= nil
    delete_button_id    ||= "delete_button"
    # we have to use eval rather than refinery.send because this url may not exist for HTTP GET
    delete_url          ||= eval("refinery.#{Refinery.route_for_model(f.object.class)}(#{f.object.id})")
  end
-%>
<% if from_dialog? %>
<input type='hidden' name='modal' value='true' />
<input type='hidden' name='dialog' value='true' />
<% end %>

<div class='form-actions<%= ' form-actions-dialog' if from_dialog? %>'>
  <div class='form-actions-left'>
    <%= submit_tag submit_button_text,
                   :id => submit_button_id,
                   :name => nil,
                   :class => "wymupdate button",
                   :tooltip => submit_button_title unless hide_submit %>

    <%= render '/refinery/admin/continue_editing', :f => f if continue_editing -%>
    <%= hidden_field_tag :continue_editing, false if continue_editing %>

    <%= local_assigns[:before_cancel_button] -%>

    <%= link_to(cancel_button_text, cancel_url,
                :title => cancel_title,
                :id => cancel_button_id,
                :class => "close_dialog button") unless hide_cancel %>

    <%= local_assigns[:after_cancel_button] -%>
    <i id='spinner' class='loading_icon hidden_icon'></i>
  </div>
  <div class='form-actions-right'>
    <%= local_assigns[:before_delete_button] -%>
    <%= link_to(delete_button_text, delete_url,
                :title => delete_title,
                :id => delete_button_id,
                :method => :delete,
                :data => {
                  :confirm => delete_confirmation
                },
                :class => "button confirm-delete") unless hide_delete %>
    <%= local_assigns[:after_delete_button] -%>
  </div>
</div>
